package com.justcs.mapper;

import com.justcs.entity.Conference;
import com.justcs.entity.ConferenceWithBLOBs;
import com.justcs.entity.IssueLastmeet;
import com.justcs.view.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ConferenceMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(ConferenceWithBLOBs record);

    int insertSelective(ConferenceWithBLOBs record);

    ConferenceWithBLOBs selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(ConferenceWithBLOBs record);

    int updateByPrimaryKeyWithBLOBs(ConferenceWithBLOBs record);

    int updateByPrimaryKey(Conference record);


    /**
     * 查询我的所有的预约（首页展示）
     * @param recorderid
     * @return
     */
    @Select({
            "<script>",
            "select\n" +
                    "c.id as confid,\n" +
                    "c.confname as confname,\n" +
                    "s.id as statusid,\n" +
                    "s.confstatus as confstatus,\n" +
                    "r.starttime as starttime,\n" +
                    "r.endtime as endtime\n" +
                    "from conference c \n" +
                    "\tjoin confmeetingroom r on (c.id = r.confid)\n" +
                    "\tjoin confstatus s on (c.confstatusid = s.id)",
            "where r.endtime >= now()",
            "<if test='recorderid!=null and recorderid!=&apos;&apos;'>",
            "and c.recorderid=#{recorderid}",
            "</if>",
            "order by r.starttime asc",
            "</script>"
    })
    List<MyOrderView> selectAllMyOrders(@Param("recorderid")String recorderid);


    /**
     * 查询即将开始的会议（首页展示）
     * @param workerid
     * @return
     */
    @Select({
            "<script>",
            "select\n" +
                    "q.confid,\n" +
                    "q.confname,\n" +
                    "q.starttime,\n" +
                    "q.endtime,\n" +
                    "q.confstatusid as statusid,\n" +
                    "q.confstatus as confstatus\n" +
                    "from (\n" +
                    "\tSELECT id as attid,\n" +
                    "\tworkerid,\n" +
                    "\tconfid\n" +
                    "\tFROM\n" +
                    "\t\tattendes \n" +
                    "\tWHERE\n" +
                    "\t\t1=1",
            "<if test='workerid!=null and workerid!=&apos;&apos;'>",
            "and workerid=#{workerid}",
            "</if>",
            ") p join (\n" +
                    "\tselect c.id as confid,\n" +
                    "\t\tc.confname,\n" +
                    "\t\tr.starttime,\n" +
                    "\t\tr.endtime,\n" +
                    "\t\tc.confstatusid,\n" +
                    "\t\ts.confstatus\n" +
                    "\tfrom conference c\n" +
                    "\t\tjoin confmeetingroom r on (c.id = r.confid)\n" +
                    "\t\tjoin confstatus s on (c.confstatusid= s.id)\n" +
                    "\twhere\n" +
                    "\t\tr.starttime > now()\n" +
                    ") q on (q.confid = p.confid)\n" +
                    "order by q.starttime asc",
            "</script>"
    })
    List<MyOrderView> selectAllCommingOrders(@Param("workerid")String workerid);



    /**
     * 查询会议的所有信息
     */
    @Select({
            "<script>",
            "select \n" +
                    "c.id as confid,\n" +
                    "c.confname as confname,\n" +
                    "s.semestername,\n" +
                    "l.levelname,\n" +
                    "c.hosterid,\n" +
                    "c.hoster,\n" +
                    "c.recorderid,\n" +
                    "c.recorder,\n" +
                    "p.starttime,\n" +
                    "p.endtime,\n" +
                    "r.id as roomid,\n" +
                    "r.roomname,\n" +
                    "c.conclusion\n" +
                    "from conference c \n" +
                    "\tjoin semester s on (c.semesterid = s.id)\n" +
                    "\tjoin conflevel l on (c.conflevelid = l.id)\n" +
                    "\tjoin confmeetingroom p on (c.id = p.confid)\n" +
                    "\tjoin meetingroom r on (p.meetroomid = r.id)",
            "where 1=1",
            "<if test='confid!=null and confid!=&apos;&apos;'>",
            "and c.id=#{confid}",
            "</if>",
            "</script>"
    })
    BasicConfInfoView selectbasicconf(@Param("confid")String confid);


    /**
     * 查询会议的列席人员
     * @param confid
     * @return
     */
    @Select({
            "<script>",
            "select\n" +
                    "a.workerid,\n" +
                    "u.usrname,\n" +
                    "a.hasattend\n" +
                    "from conference c\n" +
                    "\tjoin attendes a on (c.id = a.confid)\n" +
                    "\tjoin userinfo u on (a.workerid = u.accid)",
            "where 1=1",
            "<if test='confid!=null and confid!=&apos;&apos;'>",
            "and c.id=#{confid}",
            "</if>",
            "</script>"
    })
    List<ListAttendersView> selectAttendsList(@Param("confid")String confid);

    /**
     * 查询会议的属性
     * @param confid
     * @return
     */
    @Select({
            "<script>",
            "select\n" +
                    "c.id as confid,\n" +
                    "t.attrname,\n" +
                    "t.attrdes\n" +
                    "from conference c \n" +
                    "\tjoin confattr a on (c.id = a.confid)\n" +
                    "\tjoin confattributes t on (a.confattrid = t.id)",
            "where 1=1",
            "<if test='confid!=null and confid!=&apos;&apos;'>",
            "and c.id=#{confid}",
            "</if>",
            "</script>"
    })
    List<ConfAttributesListView> selectConfAttrList(@Param("confid")String confid);


    /**
     * 查询会议议题采集表基本信息
     * @param confid
     * @return
     */
    @Select({
            "<script>",
            "select \n" +
                    "m.collegeleader,\n" +
                    "m.id as collectid,\n" +
                    "c.id as confid,\n" +
                    "m.colltime,\n" +
                    "m.termyear,\n" +
                    "m.meetweeks \n" +
                    "from meetingcollect m \n" +
                    "\tjoin conference c on (m.id = c.meetcollectid)",
            "where 1=1",
            "<if test='confid!=null and confid!=&apos;&apos;'>",
            "and c.id=#{confid}",
            "</if>",
            "</script>"
    })
    ConfCollectBasicInfoView selectCollectView(@Param("confid")String confid);


    /**
     * 查询上次会议所提议题
     * @param confid
     * @return
     */
    @Select({
            "<script>",
            "select \n" +
                    "a.collectid,\n" +
                    "l.id as issuelastid,\n" +
                    "l.maincontent\n" +
            "from (\n" +
                "\tselect  \n" +
                "\t\tm.id as collectid,\n" +
                "\t\tc.id as confid \n" +
                "\tfrom meetingcollect m \n" +
                "\t\tjoin conference c on (m.id = c.meetcollectid)",
            "where 1=1",
                    "<if test='confid!=null and confid!=&apos;&apos;'>",
                    "and c.id=#{confid}",
                    "</if>",
            ") a join issuelastmeet l on (a.collectid = l.meetcollid)",
            "</script>"
    })
    List<ConfLastIssueView> selectLastIssueList(@Param("confid")String confid);


    /**
     * 查询本次会议需要解决的议题
     * @param confid
     * @return
     */
    @Select({
            "<script>",
            "select \n" +
                    "a.collectid,\n" +
                    "l.id as issuecurrent,\n" +
                    "l.mainconent\n" +
                    "from (\n" +
                    "\tselect  \n" +
                        "\t\tm.id as collectid,\n" +
                        "\t\tc.id as confid \n" +
                        "\tfrom meetingcollect m \n" +
                        "\t\tjoin conference c on (m.id = c.meetcollectid)",
                    "where 1=1",
                        "<if test='confid!=null and confid!=&apos;&apos;'>",
                        "and c.id=#{confid}",
                        "</if>",
            ") a join issuecurmeet l on (a.collectid = l.meetcollid)",
            "</script>"
    })
    List<ConfCurIssueView> selectCurIssueList(@Param("confid")String confid);


    /**
     * 查询建议解决的方案
     * @param confid
     * @return
     */
    @Select({
            "<script>",
            "select \n" +
                    "a.collectid,\n" +
                    "l.id as issuecurrent,\n" +
                    "l.maincontent\n" +
                    "from (\n" +
                    "\tselect  \n" +
                    "\t\tm.id as collectid,\n" +
                    "\t\tc.id as confid \n" +
                    "\tfrom meetingcollect m \n" +
                    "\t\tjoin conference c on (m.id = c.meetcollectid)",
                    "where 1=1",
                        "<if test='confid!=null and confid!=&apos;&apos;'>",
                        "and c.id=#{confid}",
                        "</if>",
            ") a join suggestion l on (a.collectid = l.meetcollid)",
            "</script>"
    })
    List<ConfSuggestionView> selectSuggesList(@Param("confid")String confid);


    /**
     * 查询会议记录内容以及录音列表内容
     * @param confid
     * @return
     */
    @Select({
            "select \n" +
                    "\tt.titleid as titleid,\n" +
                    "\tr.id as recordid,\n" +
                    "\tv.id as voiceid,\n" +
                    "\tt.titlename as titlename,\n" +
                    "\tr.speakerid as speakerid,\n" +
                    "\tr.speakername as speakername,\n" +
                    "\tr.speaking as speaking,\n" +
                    "\tv.voiceurl\n" +
                    "from (\n" +
                    "\tselect \n" +
                    "\t\tid as titleid,\n" +
                    "\t\tconftitlecnt as titlename\n" +
                    "\tfrom conftitle t \n" +
                    "\twhere t.confid = #{confid}\n" +
                    ") t left join conftitlerecord r  on (r.conftitleid = t.titleid)\n" +
                    "left join voicerecord v on (r.id = v.conftitlerecordid)\n" +
                    "order by t.titleid, r.speaktime"
    })
    List<ConfRecVoicDetailView> selectConfRecVoic(@Param("confid")String confid);


}